package p270jp.pxv.android.model;

import android.net.Uri;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import p090d0.C2518n;
import p325m0.MutabilityOwnership;
import p350mp.Timber;
import p452qn.StringNumberConversions;
import p546ug.PixivDeeplinkMatcher;
import p629xm._Collections;
import p648yf.PixivDeeplink;
import p676zh.PixivRestfulUriMatcher;
import p676zh.PixivRestfulUriParser;

/* renamed from: jp.pxv.android.model.RoutingParameter */
/* loaded from: classes2.dex */
public class RoutingParameter implements Serializable {
    private static final String SCHEME_MEMBER = "/member.php";
    private static final String SCHEME_MEMBER_ILLUST = "/member_illust.php";
    private static final String SCHEME_NOVEL_MEMBER = "/novel/member.php";
    private static final String SCHEME_NOVEL_SHOW = "/novel/show.php";
    private static final String SCHEME_PREMIUM_LP = "/premium/android";

    /* renamed from: id */
    private long f19136id;
    private Routing routing;
    private final String transferUrl;

    public RoutingParameter(Routing routing) {
        this.routing = routing;
        this.transferUrl = null;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    public static RoutingParameter convertRoutingParameter(Uri uri) {
        char c;
        PixivDeeplink aVar;
        RoutingParameter routingParameter;
        Long p;
        long idByQuery = getIdByQuery(uri);
        String path = uri.getPath();
        Objects.requireNonNull(path);
        switch (path.hashCode()) {
            case 100342163:
                if (path.equals(SCHEME_MEMBER)) {
                    c = 0;
                    break;
                }
                c = 65535;
                break;
            case 752453638:
                if (path.equals(SCHEME_NOVEL_MEMBER)) {
                    c = 1;
                    break;
                }
                c = 65535;
                break;
            case 1717548712:
                if (path.equals(SCHEME_PREMIUM_LP)) {
                    c = 2;
                    break;
                }
                c = 65535;
                break;
            case 1959427945:
                if (path.equals(SCHEME_NOVEL_SHOW)) {
                    c = 3;
                    break;
                }
                c = 65535;
                break;
            case 2022987725:
                if (path.equals(SCHEME_MEMBER_ILLUST)) {
                    c = 4;
                    break;
                }
                c = 65535;
                break;
            default:
                c = 65535;
                break;
        }
        switch (c) {
            case 0:
                if (idByQuery > 0) {
                    return new RoutingParameter(Routing.USER, idByQuery);
                }
                break;
            case 1:
                if (idByQuery > 0) {
                    return new RoutingParameter(Routing.USER, idByQuery);
                }
                break;
            case 2:
                return new RoutingParameter(Routing.PREMIUM, idByQuery);
            case 3:
                if (idByQuery > 0) {
                    return new RoutingParameter(Routing.NOVEL, idByQuery);
                }
                break;
            case 4:
                long illustIdByQuery = getIllustIdByQuery(uri);
                if (illustIdByQuery > 0) {
                    return new RoutingParameter(Routing.ILLUST, illustIdByQuery);
                }
                if (idByQuery > 0) {
                    return new RoutingParameter(Routing.USER, idByQuery);
                }
                break;
        }
        RoutingParameter restfulRouter = restfulRouter(uri);
        if (restfulRouter != null) {
            return restfulRouter;
        }
        PixivRestfulUriParser bVar = (PixivRestfulUriParser) C2518n.m7641d(PixivRestfulUriParser.class);
        Objects.requireNonNull(bVar);
        String path2 = uri.getPath();
        RoutingParameter routingParameter2 = null;
        if (path2 == null) {
            aVar = null;
        } else {
            List<PixivDeeplinkMatcher> list = bVar.f31481b;
            ArrayList arrayList = new ArrayList();
            for (PixivDeeplinkMatcher aVar2 : list) {
                PixivDeeplink a = aVar2.mo1738a(path2);
                if (a != null) {
                    arrayList.add(a);
                }
            }
            aVar = (PixivDeeplink) _Collections.m696R(arrayList);
        }
        if (aVar instanceof PixivDeeplink.C7339i) {
            routingParameter = new RoutingParameter(Routing.USER_WORK_ILLUSTRATIONS, ((PixivDeeplink.C7339i) aVar).f30877a);
        } else if (aVar instanceof PixivDeeplink.C7340j) {
            routingParameter = new RoutingParameter(Routing.USER_WORK_MANGA, ((PixivDeeplink.C7340j) aVar).f30879a);
        } else if (aVar instanceof PixivDeeplink.C7341k) {
            routingParameter = new RoutingParameter(Routing.USER_WORK_NOVELS, ((PixivDeeplink.C7341k) aVar).f30881a);
        } else if (aVar instanceof PixivDeeplink.C7335e) {
            routingParameter = new RoutingParameter(Routing.USER_BOOKMARKS_ARTWORKS, ((PixivDeeplink.C7335e) aVar).f30873a);
        } else if (aVar instanceof PixivDeeplink.C7336f) {
            routingParameter = new RoutingParameter(Routing.USER_BOOKMARKS_NOVELS, ((PixivDeeplink.C7336f) aVar).f30874a);
        } else if (aVar instanceof PixivDeeplink.C7337g) {
            routingParameter = new RoutingParameter(Routing.USER_FOLLOWING, ((PixivDeeplink.C7337g) aVar).f30875a);
        } else if (aVar instanceof PixivDeeplink.C7333c) {
            routingParameter = new RoutingParameter(Routing.UNLISTED_WORK, ((PixivDeeplink.C7333c) aVar).f30871a);
        } else {
            routingParameter = aVar instanceof PixivDeeplink.C7338h ? new RoutingParameter(Routing.USER_REQUESTS, ((PixivDeeplink.C7338h) aVar).f30876a) : null;
        }
        if (routingParameter == null) {
            PixivRestfulUriMatcher aVar3 = bVar.f31480a;
            Objects.requireNonNull(aVar3);
            int match = aVar3.f31479a.match(uri);
            if (match == -1) {
                Timber.f23100a.mo3515o(MutabilityOwnership.m3739s("該当するUriパターンが存在しなかった: ", uri), new Object[0]);
            } else if (match == 1 || match == 2) {
                String lastPathSegment = uri.getLastPathSegment();
                if (!(lastPathSegment == null || (p = StringNumberConversions.m2757p(lastPathSegment)) == null)) {
                    routingParameter2 = new RoutingParameter(Routing.USER, p.longValue());
                }
            } else {
                Timber.f23100a.mo3525d(MutabilityOwnership.m3739s("想定外のパターンが PixivRestfulUriMatcher に定義されている。 pattern: ", Integer.valueOf(match)), new Object[0]);
            }
            routingParameter = routingParameter2;
        }
        if (routingParameter != null) {
            return routingParameter;
        }
        return new RoutingParameter(Routing.NONE);
    }

    private static long convertStringToLong(String str) {
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException unused) {
            return -1;
        }
    }

    private static long getIdByQuery(Uri uri) {
        return (long) getQueryValue(uri, "id");
    }

    private static long getIllustIdByQuery(Uri uri) {
        return (long) getQueryValue(uri, "illust_id");
    }

    private static int getQueryValue(Uri uri, String str) {
        String queryParameter = uri.getQueryParameter(str);
        if (queryParameter == null) {
            return -1;
        }
        try {
            return Integer.parseInt(queryParameter);
        } catch (NumberFormatException unused) {
            return -1;
        }
    }

    private static RoutingParameter restfulRouter(Uri uri) {
        List<String> pathSegments = uri.getPathSegments();
        if (pathSegments.size() == 2 && pathSegments.get(0).equals("artworks")) {
            long convertStringToLong = convertStringToLong(pathSegments.get(1));
            if (convertStringToLong > 0) {
                return new RoutingParameter(Routing.ILLUST, convertStringToLong);
            }
        }
        if (pathSegments.size() != 3 || !pathSegments.get(1).equals("artworks")) {
            return null;
        }
        long convertStringToLong2 = convertStringToLong(pathSegments.get(2));
        if (convertStringToLong2 > 0) {
            return new RoutingParameter(Routing.ILLUST, convertStringToLong2);
        }
        return null;
    }

    public long getId() {
        return this.f19136id;
    }

    public Routing getRouting() {
        return this.routing;
    }

    public String getTransferUrl() {
        return this.transferUrl;
    }

    public boolean isShouldFinishActivity() {
        return this.transferUrl == null;
    }

    public void setId(long j) {
        this.f19136id = j;
    }

    public void setRouting(Routing routing) {
        this.routing = routing;
    }

    public RoutingParameter(Routing routing, long j) {
        this.routing = routing;
        this.f19136id = j;
        this.transferUrl = null;
    }

    public RoutingParameter(Routing routing, String str) {
        this.routing = routing;
        this.f19136id = 0;
        this.transferUrl = str;
    }
}
